package com.exp.bookhouse.controller.admin;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.exp.bookhouse.pojo.Order;
import com.exp.bookhouse.service.OrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

@Api(value = "订单管理接口",tags = "管理员管理订单操作")
@Controller
@RequestMapping("/admin")
public class OrderControllerAdmin {

    @Autowired
    private OrderService orderService;

    @ApiOperation(value = "查询订单列表")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "p", value = "页数", required = false, dataType = "Int"),
            @ApiImplicitParam(paramType = "query", name = "s", value = "显示记录数", required = false, dataType = "Int")
    })
    @GetMapping("/toOrder")
    public String toOrder(@RequestParam(value = "p", required = false, defaultValue = "1")Integer page,
                             @RequestParam(value = "s", required = false, defaultValue = "5")Integer size,
                             Model model){
        IPage<Order> iPage = orderService.queryOrderByPage(page,size);
        model.addAttribute("iPage",iPage);
        return "order";
    }


    @ApiOperation(value = "查询订单和细节")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "id", value = "订单id", required = true, dataType = "Long")
    })
    @GetMapping("/queryOrderDetail/{id}")
    public String queryOrderDetail(@PathVariable("id")Long id, Model model){
        Order order = orderService.queryOrderDetail(id);
        model.addAttribute("order",order);
        return "orderDetail";
    }


}
